package com.example.oppo;

import android.graphics.Color;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.oppo.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

public class SecondActivity extends AppCompatActivity {
    private EditText mEditText;
    private ImageButton mImageButton;
    private RadioGroup mRadioGroup;
    private RadioButton mRadioButton1;
    private RadioButton mRadioButton2;
    private RadioButton mRadioButton3;
    private RadioButton mRadioButton4;
    private CheckBox mCheckBox1;
    private CheckBox mCheckBox2;
    private CheckBox mCheckBox3;
    private Switch mSwitch;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtils.i("test111111111", "--------SecondActivity onCreate--------- ");
        List list=new ArrayList();
        list.add(1);
        LogUtils.e("test11111", "--------------SecondActivity list.get(0)-------"+list.get(0));
        setContentView(R.layout.activity_second);
        mEditText = findViewById(R.id.edittext);
        mImageButton = findViewById(R.id.imagebutton);
        mImageButton.setVisibility(View.GONE);
        mImageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditText.setText("");
            }
        });
        mEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                mImageButton.setVisibility(s.length() > 0 ? View.VISIBLE : View.GONE);
            }
        });

        mRadioGroup = findViewById(R.id.radiogroup);
        mRadioButton1 = findViewById(R.id.rb1);
        mRadioButton2 = findViewById(R.id.rb2);
        mRadioButton3 = findViewById(R.id.rb3);
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (mRadioButton3.isChecked()) {
                    mRadioButton3.setBackground(getDrawable(R.mipmap.blue));
                    mRadioButton3.setTextColor(Color.parseColor("#ff4562"));
                } else {
                    mRadioButton3.setBackground(getDrawable(R.mipmap.zise));
                    mRadioButton3.setTextColor(Color.parseColor("#454562"));
                }
                if (mRadioButton1.isChecked()) {
                    mRadioButton1.setButtonDrawable(getDrawable(R.mipmap.bg_delete));
                } else {
                    mRadioButton1.setButtonDrawable(getDrawable(R.mipmap.bg_delete_pressed));
                }
            }
        });

        mCheckBox1 = findViewById(R.id.cb1);
        mCheckBox2 = findViewById(R.id.cb2);
        mCheckBox3 = findViewById(R.id.cb3);
        mCheckBox1.setChecked(true);
        mCheckBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    mCheckBox1.setBackground(getDrawable(R.mipmap.blue));
                } else {
                    mCheckBox1.setBackground(getDrawable(R.mipmap.red));
                }
            }
        });
        mCheckBox2.setButtonDrawable(getDrawable(R.drawable.radio_checked_seletor));
        mCheckBox3.setBackgroundResource(R.drawable.radio_bg_seletor);

        mSwitch = findViewById(R.id.switch1);
        mSwitch.setThumbDrawable(getDrawable(R.mipmap.bg_delete_pressed));
        mSwitch.setTrackDrawable(getDrawable(R.mipmap.red));
        mSwitch.setTextOn("on");
        mSwitch.setTextOff("off");
        mSwitch.setShowText(false);
        mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                LogUtils.d("TEST", "当前开关状态为 : " + isChecked );
            }
        });
    }
}
